home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 1 / The Arsenal Files (Arsenal Computer).ISO / genprog / msjfeb94.exe / CQA.ZIP / MDICOLOR.CPP next >
C/C++ Source or Header  |  1994-02-01  |  3KB  |  117 lines

  1. //////////////////
  2. // Sample MFC application showing how to set the 
  3. // background color for MDI child windows
  4. // 
  5.  
  6. #include <afxwin.h> 
  7. #include <afxext.h>
  8. #include "mdicolor.h"
  9.  
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char BASED_CODE THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. ////////////////////////////////////////////////////////////////
  16. // Document and main frame classes are trivial
  17. //
  18. IMPLEMENT_DYNCREATE(CRedDoc, CDocument)
  19. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  20.  
  21.  
  22. ////////////////////////////////////////////////////////////////
  23. // Application class
  24. //
  25. BEGIN_MESSAGE_MAP(CRedApp, CWinApp)
  26.    ON_COMMAND(ID_FILE_NEW_VIEW, OnNewView)
  27.    ON_COMMAND(ID_FILE_NEW_FORM, OnNewForm)
  28. END_MESSAGE_MAP()
  29.  
  30. CRedApp NEAR theApp;
  31.  
  32. BOOL CRedApp::InitInstance()
  33. {
  34.    // Create template for ordinary view window
  35.    m_pViewTemplate = new CMultiDocTemplate(IDR_VIEWTYPE,
  36.       RUNTIME_CLASS(CRedDoc),
  37.       RUNTIME_CLASS(CMDIChildWnd),
  38.       RUNTIME_CLASS(CRedView));
  39.    AddDocTemplate(m_pViewTemplate);
  40.  
  41.    // Create template for form view
  42.    m_pFormTemplate = new CMultiDocTemplate(IDR_FORMTYPE,
  43.       RUNTIME_CLASS(CRedDoc),
  44.       RUNTIME_CLASS(CMDIChildWnd),
  45.       RUNTIME_CLASS(CRedFormView));
  46.    AddDocTemplate(m_pFormTemplate);
  47.  
  48.    // Create main MDI Frame window
  49.    CMainFrame* pMainFrame = new CMainFrame;
  50.    if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  51.       return FALSE;
  52.    pMainFrame->ShowWindow(m_nCmdShow);
  53.    pMainFrame->UpdateWindow();
  54.    m_pMainWnd = pMainFrame;
  55.  
  56.    return TRUE;
  57. }
  58.  
  59. void CRedApp::OnNewView()
  60. {
  61.    m_pViewTemplate->OpenDocumentFile(NULL);  
  62. }
  63.  
  64. void CRedApp::OnNewForm()
  65. {
  66.    m_pFormTemplate->OpenDocumentFile(NULL);  
  67. }
  68.  
  69. ////////////////////////////////////////////////////////////////
  70. // View class sets the background color 
  71. // by registering a new window class
  72. //
  73. IMPLEMENT_DYNCREATE(CRedView, CView)
  74.  
  75. CString CRedView::sClassName;
  76.  
  77. //////////////////
  78. // If the window class is not yet registered, register it.
  79. //
  80. BOOL CRedView::PreCreateWindow(CREATESTRUCT& cs)
  81. {
  82.    if (sClassName.IsEmpty())
  83.       sClassName = AfxRegisterWndClass(CS_DBLCLKS, 0, theApp.GetRedBrush());
  84.    cs.lpszClass = sClassName;
  85.    return CView::PreCreateWindow(cs);
  86. }
  87.  
  88. //////////////////
  89. // Form view class sets the background color via WM_CTLCOLOR message
  90. //
  91. IMPLEMENT_DYNCREATE(CRedFormView, CFormView)
  92.  
  93. BEGIN_MESSAGE_MAP(CRedFormView, CFormView)
  94.    ON_WM_CTLCOLOR()
  95. END_MESSAGE_MAP()
  96.  
  97. CRedFormView::CRedFormView() : CFormView(IDD_DIALOG1)
  98. {
  99.  
  100. }
  101.  
  102. HBRUSH CRedFormView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nWhich)
  103. {
  104. #ifdef _DEBUG
  105.    static const char* CTLCOLORNAMES[] = {
  106.       "CTLCOLOR_MSGBOX",   "CTLCOLOR_EDIT",  "CTLCOLOR_LISTBOX",
  107.       "CTLCOLOR_BTN",      "CTLCOLOR_DLG",   "CTLCOLOR_SCROLLBAR",
  108.       "CTLCOLOR_STATIC",
  109.    };
  110.    TRACE("CRedFormView::OnCtlColor: nWhich=%s\n", CTLCOLORNAMES[nWhich]);
  111. #endif
  112.  
  113.    return (nWhich==CTLCOLOR_DLG) ? theApp.GetRedBrush() 
  114.       : CFormView::OnCtlColor(pDC, pWnd, nWhich);
  115. }
  116.  
  117.